package com.shop.controller;


import com.alibaba.fastjson.JSONObject;
import com.shop.entity.PmsAttr;
import com.shop.service.PmsAttrService;
import com.shop.vo.ResultJson;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 分类属性表 前端控制器
 * </p>
 *
 * @author lpx610
 * @since 2023-11-04
 */
@RestController
@RequestMapping("/pmsAttr")
public class PmsAttrController {

    @Resource
    private PmsAttrService pmsAttrService;

    @GetMapping("/getByCategoryId")
    public ResultJson<List<PmsAttr>> getByCategoryId(String categoryId) {
        return ResultJson.success(pmsAttrService.getByCategoryId(categoryId));
    }

    @PostMapping("/add")
    public ResultJson<Boolean> add(String[] names, String categoryId, Integer type) {
        return ResultJson.success(pmsAttrService.add(names, categoryId, type), "添加属性成功");
    }

    @PostMapping("/update")
    public ResultJson<Boolean> update(String id, String name, Integer type) {
        return ResultJson.success(pmsAttrService.update(id, name, type), "修改属性成功");
    }

    @GetMapping("/delete")
    public ResultJson<Boolean> delete(String id) {
        return ResultJson.success(pmsAttrService.delete(id), "删除属性成功");
    }

}
